package servlet;

import bean.Result;
import biz.BizException;
import biz.UserBiz;
import com.google.gson.Gson;
import dao.ChangePwdDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "ChangePwdServlet", value = "/ChangePwdServlet.s")
public class ChangePwdServlet extends HttpServlet {
    private UserBiz biz = new UserBiz();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String oldpwd = request.getParameter("oldpwd");
        String againpwd = request.getParameter("againpwd");
        final String newpwd = request.getParameter("newpwd");
        String id = request.getParameter("uid");
        Result result ;


        try {
            biz.changePwd(oldpwd,newpwd,againpwd,id);
            result = new Result(1,"修改成功!",null);
        } catch (BizException e) {
            e.printStackTrace();
            result = new Result(0,e.getMessage(),null);

        }
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);

    }

}
